

class typecheck: 
    def __init__(self,i): 
        self.__type__ = type(i)
        print type(i)
    def __setattr__(self,name,value): 
        if (name.find('__type__') != 0) and (type(value) != self.__type__): 
            raise TypeError, "(%s) is not %s"%(name,self.__type__.__name__) 
        self.__dict__[name]=value 
 
 
if __name__ == '__main__': 
    import sys 
    try: 
        my_int = typecheck(1) 
        my_int.x = 3 
        my_int.y = 4 
        my_int.z = 5 
#        my_int.h = 'hey' 
        print type(my_int), type(typecheck)
    except: 
        print sys.exc_type, sys.exc_value 
 
    try: 
        my_string = typecheck('') 
        my_int.s = 'hello' 
        my_int.t = 'byebye' 
        my_int.u = 3 
    except: 
        print sys.exc_type, sys.exc_value 

